<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            border-radius: 50%;
            background-color: aquamarine;
            position: fixed;
        }
    </style>
</head>

<body>
    <div class="smallball"></div>
    <script>
        var div = document.querySelector(".smallball"),
            x = 0,
            y = 0,
            moveLeft = 2,
            moveTop = 2;
        div.onclick = function () {
            setInterval(function () {
                x += moveLeft;
                y += moveTop;
                if (x >= document.documentElement.clientWidth - 100) {
                    x = document.documentElement.clientWidth - 100;
                    moveLeft = -moveLeft;
                }
                if (x <= 0) {
                    x = 0;
                    moveLeft = -moveLeft;
                }
                if (y >= document.documentElement.clientHeight - 100) {
                    y = document.documentElement.clientHeight - 100;
                    moveTop = -moveTop;
                }
                if (y <= 0) {
                    y = 0;
                    moveTop = -moveTop;
                }
                div.style.left = x + "px";
                div.style.top = y + "px";
            }, 10);
        } 
    </script>
</body>

</html>